package com.kehongborui.ticket.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * @author zhang peng yang ming
 * @create 2018-08-16 19:46
 */
@Controller
@RequestMapping("/file")
public class UploadController {
    @RequestMapping("/upload")
    public String upload(MultipartFile multipartFile, HttpServletRequest request) throws IOException {
        String originalName = multipartFile.getOriginalFilename();
        String realPath = request.getServletContext().getRealPath("/");
        File file = new File(realPath + "/" + originalName);
        multipartFile.transferTo(file);

        request.setAttribute("fileUrl", "/static/" + originalName);
        return "result";
    }
}
